document.querySelector('#btn-login').addEventListener('click', async e => {
    const data = serialize(document.querySelector('.login-form'), { hash: true, empty: true })
    if (!data.username)
        return showToast('请输入用户名')
    if (data.username.length < 8 || data.username.length > 30)
        return showToast('用户名不符合要求')
    if (!data.password)
        return showToast('请输入密码')
    if (data.password.length < 6 || data.password.length > 30)
        return showToast('密码不符合要求')

    // 发送登录请求
   try{
    const res = await axios.post('/login',data)
    // 存储用户名
    
    const username = res.data.username
    const token = res.data.token
    localStorage.setItem('username', username)
    localStorage.setItem('token', token)
    showToast(res.message)
    setTimeout(()=>{
        location.href = './index.html'
    },800)
   } catch(err){
    showToast(err.response.data.message)
   }

})